public class Solution701 {

    public static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode() {
        }

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }

    public TreeNode insertIntoBST(TreeNode root, int val) {
        if (root==null){
            return new TreeNode(val);
        }
        if (val<root.val){
            root.left=insertIntoBST(root.left,val);
        }
        if (val>root.val){
            root.right=insertIntoBST(root.right,val);
        }
        return root;
    }

    public static void main(String[] args) {
        System.out.println(new Solution701().insertIntoBST(new TreeNode(4,new TreeNode(2,new TreeNode(1),new TreeNode(3)),new TreeNode(7)),5).right.left.val);
    }
}
